/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package hibernatedaos;

import hibentities.Customer;
import hibentities.CustomerData;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;


/**
 *
 * @author piotrek
 */
@Repository
public class UserHibernateDao {

	private SessionFactory sessionFactory;
	private HibernateTemplate hibernateTemplate;

	public UserHibernateDao(){

	}
	
	@Autowired
    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
		this.hibernateTemplate = new HibernateTemplate(sessionFactory);
    }

	/**
	 * Pobierz dane użytkownika
	 * @param id
	 * @return
	 */
	public Customer getUser( Long id ){

		return this.hibernateTemplate.get(Customer.class, id);
		
	}

	/**
	 * Aktualizacja danych klienta przez Hibernate
	 * @return boolean
	 */
	public boolean updateUser( Customer c ){

		this.hibernateTemplate.update(c);

		return true;

	}

	/**
	 * Usuwanie danych uzytkownika
	 * @return
	 */
	public boolean deleteUser( Long id ){

		Customer c = this.hibernateTemplate.get( Customer.class, id);
		this.hibernateTemplate.delete(c);

		return true;

	}
	
	/**
	 * Dodawanie nowego klienta przez Hibernate
	 * @return
	 */
	public boolean addUser( Customer customer ){

		this.hibernateTemplate.save( customer );

		return true;

	}

}
